from configparser import ConfigParser
from math import floor
import tomlkit
import tomlkit.exceptions
config = 'config'
suffix = '.toml'
def get_valid_conf_list()->list:
    ##只获取config.toml中的conf_list
    with open("config.toml",'r',encoding='utf-8') as f:
        toml = tomlkit.load(f)
    return toml['setting'].get('conf_list',"config").split("|")
def set_conf(conf:str):
    global config
    config = conf
def get_conf():
    return config+suffix
def gtoml():
    with open(get_conf(), 'r',encoding='utf-8') as f:
        return tomlkit.load(f)
def wtoml(data):
    with open(get_conf(), 'w',encoding='utf-8') as f:
        tomlkit.dump(data,f)
def gcon(section:str,option:str,default="")->str:
    try:
        with open(get_conf(),'r',encoding='utf-8') as f:
            con = tomlkit.load(f)
            return con[section][option]
    except:
        return default

def wcon(section: str, option: str, value: str):
    con = gtoml()
    con[section][option] = value
    with open(get_conf(),'w',encoding='utf-8') as f:
        tomlkit.dump(con,f)

def get_scale_num(raw)->int:
    return  floor(gcon("setting","scale")*raw)
if __name__ == "__main__":
    set_conf("config111")
    print(get_conf())

